<?php
namespace Home\Controller;


class WeixinController extends HomeController {

    
    public function index(){
    	
        $appid = C('WXAPPID');
        $appsecret = C('WXAPPSECRET');
        
       
        $cateid= C('WXCATEID');
        $mapcate['id']=array('in',$cateid);
      
       $catearr= M('cate')->where($mapcate)->select();
       $catecount= M('cate')->where($mapcate)->count();
       $menu='';
       $menu = '{"button":[{"type":"click","name":"每日精选","key":"newblog"},{"name":"精选分类","sub_button":[{';
       
      foreach ($catearr as $key =>$vo){
      	
      //	$cate[$key]=array("type" => "view",'name' => urlencode('"'.$vo['name'].'"'),"url" => urlencode('"'.ZSU('/artlist/'.$vo['id'],'Index/artlist',array('cid'=>$vo['id']))).'"');
      	$menu .='"type":"view","name":"'.$vo['name'].'","url":"'.(is_ssl()?'https://':'http://').$_SERVER['HTTP_HOST'].'/'.C('WEB_DIR').'/'.ZSU('/artlist/'.$vo['id'],'Index/artlist',array('cid'=>$vo['id'])).'"';
      	if($key!=$catecount-1){
      	$menu .='},{';
      	}
      }
      $menu .='}]}]}';
        
     
       
        $weixin = new \Common\Weixin\Weixin($appid, $appsecret);
        
        if(C('CREATMENU')==1){
        	$msg=$weixin->deleteMenu();
        	$msg1=$weixin->creatMenu($menu);
        	
        	
        	
        }
        
       
     
        $typeData = $weixin->getTypedata();
        $typeData['met'] = 'index';
        $this->assign('data', $typeData);
        $this->display();
        
    }

}